package com.trademark.script.methods;

import java.util.ArrayList;

import org.rsbuddy.tabs.Inventory;

import com.rsbuddy.script.methods.Menu;
import com.rsbuddy.script.methods.Mouse;
import com.rsbuddy.script.task.Task;
import com.rsbuddy.script.util.Random;
import com.rsbuddy.script.wrappers.Item;

public class Inv {

	/*
	 * @param minSpeed The minimum speed for the mouse to travel
	 * 
	 * @param maxSpeed The maximum speed for the mouse to travel
	 * 
	 * @param hop Uses Mouse#hop if true; otherwise uses Mouse#move
	 */
	public static void dropAll(final int minSpeed, final int maxSpeed,
			final boolean hop) {
		ArrayList<Integer> droppedItems = new ArrayList<Integer>();
		for (Item item : Inventory.getItems()) {
			Mouse.setSpeed(Random.nextInt(minSpeed, maxSpeed));
			if (hop) {
				if (item != null) {
					if (!droppedItems.contains(item)) {
						if (!Menu.isOpen()) {
							if (item.getComponent().contains(
									Mouse.getLocation())) {
								item.click(false);
								Task.sleep(100, 125);
							} else {
								Mouse.hop(item.getComponent().getLocation());
								Task.sleep(35, 50);
								item.click(false);
								Task.sleep(100, 125);
							}
						} else if (Menu.isOpen()) {
							if (Menu.contains("Drop")) {
								Menu.click("Drop");
								droppedItems.add(item.getId());
								Task.sleep(50, 75);
							} else if (!Menu.contains("Drop")) {
								Mouse.moveRandomly(Random.nextInt(100, 300));
							}
						}
					}
				}
			} else if (!hop) {
				if (item != null) {
					if (!droppedItems.contains(item)) {
						if (!Menu.isOpen()) {
							item.click(false);
							Task.sleep(100, 125);
						} else if (Menu.isOpen()) {
							if (Menu.contains("Drop")) {
								Menu.click("Drop");
								droppedItems.add(item.getId());
								Task.sleep(50, 75);
							} else if (!Menu.contains("Drop")) {
								Mouse.moveRandomly(Random.nextInt(100, 300));
							}
						}
					}
				}
			}
		}
		if (Menu.isOpen() && !Menu.contains("Drop")) {
			Menu.click("Cancel");
			Task.sleep(50, 75);
		} else if (Menu.isOpen() && Menu.contains("Drop")) {
			Menu.click("Drop");
			Task.sleep(50, 75);
		}
	}

	/*
	 * @return Returns true if inventory is empty; otherwise returns false
	 */
	public static boolean isEmpty() {
		return Inventory.getCount() == 0;
	}
}
